<!-- 页眉 -->
{include file="public/header" /}

<!-- 导航 -->
{include file="public/nav" /}

<!-- 主体 -->
<div class="layui-fluid" id="main">
    <div class="layui-row" style="margin-top: 20px">
        <div class="layui-col-md2" style="max-width: 130px;min-width: 130px; margin-right: 20px;">
            <img src="/static/img/logo_a.png" style="border: 0px;">
        </div>
        <div class="layui-col-md10">
            <form class="layui-form" action="">
                <div class="layui-form-item">
                    <div class="layui-input-inline" style="width: 500px">
                        <input name="keyword" id="keyword" lay-verify="keyword" autocomplete="off" placeholder="请输入搜索关键词，普通检索不要输入特殊符号，如: '&'、'^'、'|' 等" class="layui-input" type="text">
                    </div>
                    <div class="layui-input-inline">
                        <button class="layui-btn" lay-submit="" lay-filter="searchButton">搜一下</button>
                    </div>
                </div>
            </form>
        </div>
        <hr>
    </div>

    <div class="layui-row" style="margin-top: 20px">
        <div class="layui-col-md12">
            <blockquote class="layui-elem-quote">本次搜索到相关结果 <span id="counts"></span> 种，用时：<span id="times"></span>（秒）</blockquote>
            <div class="layui-row">
                <div class="layui-col-md12">
                    <table class="layui-hide" lay-filter="dataTable" id="dataTable"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="listTpl">
    <a href="{:url('index/publicationList')}?type={$type}&pid={{d.s_id}}" target="_blank">{{ d.sourcename }}</a>
</script>

<!-- 控制脚本 -->
<script>
    layui.use(['element', 'layer', 'form', 'table'], function(){
        var element = layui.element
            ,form = layui.form
            ,table = layui.table
            ,layer = layui.layer
            ,$ = layui.$;

        var layer_index = layer.load(0,{time: 10*1000});

        //自定义验证规则
        form.verify({
            keyword: function(value){
                if(value.length < 3){
                    return '亲，关键词太少了，多输2个字符再试试';
                }
            }
        });

        var tableIns = table.render({
            elem: '#dataTable'
            ,where: {
                keyword: $('#keyword').val()
                ,type:  '{$type}'
            }
            ,url: '/api/search/publication'
            ,method: 'post'
            ,page: true
            ,skin: 'nob'
            ,loading: true
            ,limit:10
            ,cols: [[
                {field:'sourcename', title:'母体文献名称', templet: '#listTpl'}
            ]]
            , done: function(res, curr, count){
                layer.close(layer_index);
                $('#times').html(res.times);
                //得到数据总量
                $('#counts').html(count);
            }
        });

        //监听提交
        form.on('submit(searchButton)', function(data){
            layer_index = layer.load();
            tableIns.reload({
                where: {
                    keyword: $('#keyword').val()
                    ,type:  '{$type}'
                }
                ,page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false;
        });

    });
</script>

<!-- 页脚 -->
{include file="public/footer" /}